﻿IF EXISTS ( SELECT  *
            FROM    sys.objects
            WHERE   object_id = OBJECT_ID(N'ssp_Help_upd')
                    AND type IN ( N'P', N'PC' ) ) 
    DROP PROCEDURE ssp_Help_upd
GO

SET   QUOTED_IDENTIFIER   ON
go
CREATE procedure ssp_Help_upd
(
    @MenuID int,
	@HelpID int
)
as

BEGIN
	declare @maxorder int
	declare @titleCount int
	if @HelpID > 0
		UPDATE TS_Help
		   SET HelpTitle = @HelpTitle
			  ,HelpContent = @HelpContent
			  ,HelpOrder = @HelpOrder
			  ,HelpUrls = @HelpUrls
		 WHERE HelpID = @HelpID
	ELSE
		BEGIN
			select @titleCount = count(1) from TS_Help
			 where MenuID = @MenuID
			   and HelpTitle =@HelpTitle
			if @titleCount > 1
				return -1 --标题重复

			if @HelpOrder = 0
				select @maxorder = count(1)+1 from TS_Help
				 where MenuID = @MenuID
			else
				select @maxorder = @HelpOrder

				INSERT INTO TS_Help
				   (MenuID
				   ,HelpTitle
				   ,HelpContent
				   ,HelpOrder
				   ,HelpUrls)
			   VALUES
				   (@MenuID
				   ,@HelpTitle
				   ,@HelpContent
				   ,@maxorder
				   ,@HelpUrls
				   )

		END

END  
